import $ from '../common';
Page({
  data: {
    payway:1,
    ismore:false
  },
  time:null,
  onLoad(e) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || '',
      order_uuid:e.order_uuid,
      info:JSON.parse(e.info)
    }) 
    this.getorder()
  },
  onShow() {
  },
  forma2(num) {
      return '0'.repeat(2 - String(Math.floor(num / 3600)).length) + Math.floor(num / 3600) + ':' + '0'.repeat(2 - String(Math.floor((num%3600) / 60)).length) + Math.floor((num%3600) / 60) + ':' + '0'.repeat(2 - String(Math.floor((num%3600) % 60)).length) + Math.floor((num%3600) % 60)
  },
  getorder(){
    $.get('/order/remainder/paytime',{
      zonecode:this.data.zonecode,
      order_uuid:this.data.order_uuid
    },res=>{
      this.setData({
        time: this.forma2(res.expire_seconds),
        num:res.expire_seconds,
        ismore:res.expire_seconds>0?false:true
      })
      this.timer()
    })
  },
  timer(){
    this.time=setInterval(() => {
      let num=this.data.num--
      this.setData({
        time:this.forma2(num),
      })
      if(num==0){
        clearInterval(this.time)
        this.setData({
          ismore:true
        })
      }
    }, 1000);
  },
  radioChange(e){
    this.setData({
      payway:e.detail.value
    })
  },
  pay(){
    $.requestPayment(this.data.order_uuid,()=>{
      console.log('支付成功');
    })
  }
})